s = input()
mx = 0
if len(s) == 4:
    a = [s[0], s[1], s[2], s[3], s[0:2], s[1:3], s[2:4], s[0:3], s[1:4], s]
    for i in range(len(a)):
        n = int(a[i])
        c = 0
        for i in range (1, n+1):
            if n%i == 0:
             c+=1
        if c == 2 and n != 1:
            mx = max(mx, n)
print(mx)
